<?php
declare(strict_types=1);

namespace Hesb\LaravelPlus\Traits;

use Hesb\LaravelPlus\Annotation\Inject;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Facades\Config;
use ReflectionClass;

trait Injectable {
    /**
     * @throws BindingResolutionException
     */
    public function __construct()
    {
        $reflectionClazz = new ReflectionClass($this);
        foreach ($reflectionClazz->getProperties() as $property) {
            $autowired = $property->getAttributes(Inject::class);
            if ($autowired) {
                $property->setValue($this, app()->make($property->getType()->getName()));
            }
//            $values = $property->getAttributes(Value::class);
//            if (isset($values[0])) {
//                $property->setValue($this, Config::get(($values[0])->newInstance()->pattern));
//            }
        }
    }
}
